﻿using Hue_Demo_PCL.Models;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;

namespace Hue_Demo_Phone.Converters
{

    public class ColorToOpacity : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return 0.2;

            var colorInt = (int)value;
            var opacity = .2 + (.79 * (colorInt / 255.0));
            return opacity;
        }


        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return 0;
            var opacity = (double)value;
            var colorInt = System.Convert.ToInt32(((opacity - .2) / .79) * 255);
            return colorInt;
        }
    }

    public class HueLightToColor : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            ////////////////////////////////////////////////////
            // Return a SolidColorBrush to our Path.Fill
            SolidColorBrush scb = new SolidColorBrush();

            scb.Color = Color.FromArgb(255, 255, 255, 255);
            if (value == null)
                return scb;

            ///////////////////////////////////////////////////
            // Determining that color from the color of the Hue light
            var hueL = (HueLight)value;
            
            //////////////////////////////////////////////////
            // Set the color of the SolidColorBrush using the
            //    HueLight RGB values
            scb.Color = Color.FromArgb(255,
                                System.Convert.ToByte(hueL.Red),
                                System.Convert.ToByte(hueL.Green),
                                System.Convert.ToByte(hueL.Blue));
            return scb;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
}

